//
//  MCBaseDataViewController.m
//  TLYL
//
//  Created by miaocai on 2017/10/23.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCBaseDataViewController.h"

@interface MCBaseDataViewController ()
/**listModel 模型*/
@property (nonatomic,strong) MCBaseDataModel *baseModel;

@end

@implementation MCBaseDataViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addNotification];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

//#pragma mark --添加🔍
//- (void)addNavRightBtn {
//    UIButton *btn = [[UIButton alloc] init];
//    [btn setBackgroundImage:[UIImage imageNamed:@"debss"] forState:UIControlStateNormal];
//
//    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [btn sizeToFit];
//    [btn addTarget:self action:@selector(allBtnClick:) forControlEvents:UIControlEventTouchDown];
//    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
//    self.navigationItem.rightBarButtonItem = rightItem;
//}

#pragma mark ------ Notification --------
- (void)addNotification{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadData) name:@"MCErrorWindow_Retry" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadData) name:@"MCNONetWindow_Retry" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showErrNet) name:NetworkIsReachabilityNotification object:nil];
    
}
- (void)showErrNet{
    [self.errNetWin setHidden:NO];
}
- (void)hiddenExDataView{
    [self.noDataWin setHidden: YES];
    [self.errNetWin setHidden: YES];
    [self.errDataWin setHidden: YES];
}
- (void)showExDataView{
    [self hiddenExDataView];
    [self.noDataWin setHidden: NO];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self hiddenExDataView];
}
#pragma mark --发送请求
//-(void)loadData{
//    [self hiddenExDataView];
//}
- (void)showExcaptionView:(NSDictionary *)errorCode{
    
    if ([errorCode[@"code"] isKindOfClass:[NSError class]]) {
        NSError *err = errorCode[@"code"];
        [self showExcaptionViewWithErr:err];
    }else{
        [self.errDataWin setHidden:NO];
    }
    [SVProgressHUD dismiss];
    
}
- (void)showExcaptionViewWithErr:(NSError *)err{
    [self showExcaptionViewWithErrCode:err.code];
}

- (void)showExcaptionViewWithErrCode:(NSInteger)errcode{
    [self hiddenExDataView];
    if (errcode == -1001) {
        [self.errDataWin setHidden:NO];
    } else if (errcode == -1009){
        [self.errNetWin setHidden:NO];
    }else {
        [self.errDataWin setHidden:NO];
    }
}
- (MCNoDataWindow *)noDataWin{
    if (_noDataWin == nil) {
        MCNoDataWindow *win = [[MCNoDataWindow alloc]alertInstanceWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight, G_SCREENWIDTH, G_SCREENHEIGHT- kStatusBarAndNavigationBarHeight -kTabBarHeight)];
        [self.view addSubview:win];
        _noDataWin = win;
    }
    return _noDataWin;
    
}
    
- (MCErrorWindow *)errDataWin{
    if (_errDataWin == nil) {
        MCErrorWindow *win = [[MCErrorWindow alloc]alertInstanceWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight , G_SCREENWIDTH, G_SCREENHEIGHT- kStatusBarAndNavigationBarHeight -kTabBarHeight)];
        [self.view addSubview:win];
        _errDataWin = win;
    }
    return _errDataWin;
    
}
- (MCNONetWindow *)errNetWin{
    if (_errNetWin == nil) {
        MCNONetWindow *win = [[MCNONetWindow alloc]alertInstanceWithFrame:CGRectMake(0,  kStatusBarAndNavigationBarHeight, G_SCREENWIDTH , G_SCREENHEIGHT- kStatusBarAndNavigationBarHeight -kTabBarHeight)];
        [self.view addSubview:win];
        _errNetWin = win;
    }
    return _errNetWin;
    
}

@end
